<?php
/*1.	(1)输出：This is truth:"php is the best language!"
(2)输出：$a是变量
*/

	echo "This is truth:\"php is the best language!\"";
	echo "<br>";
	echo "\$a是变量<br>";
	echo "<br><br>";


//计算并输出银行存款1000元一年后及两年后的本息总额（假设一年息为2.25，两年息为2.79）

	$capital=1000;
	$capital1=$capital*1.0225;
	$capital2=$capital1*1.0279;
	echo "一年后的本息总额：$capital1<br>两年后的本息总额：$capital2";
	echo "<br><br>";

//定义一些常量并输出，把3.14定义为pi，把root定义为user函数

define("pi","3.14");
echo pi,"<br>";

function user()
{
	echo "pi is ",pi,"<br>";
}

$root=user();

echo $root,"<br>";
echo "<br><br>";

//求一元二次方程组解
$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];
function qiujie($a,$b,$c)
{
	if(($b*$b-4*$a*$c)>=0)
	{
		$delta=$b*$b-4*$a*$c;
		$x1=(-$b+sqrt($delta))/(2*$a);
		$x2=(-$b-sqrt($delta))/(2*$a);
		echo "x1=$x1 <br>" ;
		echo "x2=$x2 <br>" ;
	}
	else
	{
		echo "此二元一次方程组无解！！！<br>";
	}
}
/* 验证*/
$tao1=1;  $tao2=2;  $tao3=1;
qiujie($tao1,$tao2,$tao3);
echo "<br><br>";


//遍历一个学生信息，包括学号、姓名、性别、电话，
$stu=array("no"=>"23333333","name"=>"ruby","sex"=>"女","tele"=>"888888888");
foreach($stu as $key => $value)
{
	echo $key."=>".$value."<br>";
}
echo "<br><br>";

//.遍历用户购物车数组中的商品编号、金额及价钱。
$woods=array(array("id"=>"001","name"=>"book","cost"=>"50"),array("id"=>"002","name"=>"bread","cost"=>"5"),array("id"=>"003","name"=>"bow1","cost"=>"10"));

for($i=0;$i<3;$i++)
{
	foreach($woods[$i] as $key => $value)
	{
		echo $key."=>".$value."&nbsp&nbsp&nbsp&nbsp";
	}
	echo "<br>";
}
echo "<br><br>";

//.表单输入年份和月份，打印该年该月距离今天的天数。（2月28天，闰年2月29天；能被4整除却不能被100整除的年份是闰年，能被400整除的也是闰年。）

$year1=$_POST['year'];
$month1=$_POST['month'];
function cal($year,$month)
{
	$all=0;
	if(($year%4==0&&$year%100!=0)||($year%400==0))
	{
		switch ($month) {
			case '1':$days=31;break;
			case '2':$days=29;break;
			case '3':$days=31;break;
			case '4':$days=30;break;
			case '5':$days=31;break;
			case '6':$days=30;break;
			case '7':$days=31;break;
			case '8':$days=31;break;
			case '9':$days=30;break;
			case '10':$days=31;break;
			case '11':$days=30;break;
			case '12':$days=31;break;
		}
	}
	else
	{
		switch ($month) {
			case '1':$days=31;break;
			case '2':$days=28;break;
			case '3':$days=31;break;
			case '4':$days=30;break;
			case '5':$days=31;break;
			case '6':$days=30;break;
			case '7':$days=31;break;
			case '8':$days=31;break;
			case '9':$days=30;break;
			case '10':$days=31;break;
			case '11':$days=30;break;
			case '12':$days=31;break;
		}
	}
	if($year==2018)
	{
		switch ($month) {
			case '1':$all=320;break;
			case '2':$all=289;break;
			case '3':$all=259;break;
			case '4':$all=228;break;
			case '5':$all=198;break;
			case '6':$all=167;break;
			case '7':$all=137;break;
			case '8':$all=106;break;
			case '9':$all=75;break;
			case '10':$all=45;break;
			case '11':$all=14;break;
			case '12':$all=16;break;
		}
		echo "距离今天",$all,"天";
	}
	elseif ($year>2018) 
	{
		for($year;$year>2018;$year--)
		{
			for($month;$month>0;$month--)
			{
				$all+=$days;
			}
		}
		$all+=320;
		echo "距离今天",$all,"天";
	}
	else
	{
		for($year;$year<2018;$year++)
		{
			for($month;$month<12;$month++)
			{
				$all+=$days;
			}
		}
		$all+=47;
		echo "距离今天",$all,"天";
	}
}
cal($year1,$month1);
echo "<br><br><br>";



//打印九九乘法表
$arr1 = array(1,2,3,4,5,6,7,8,9);  $arr2=array(1,2,3,4,5,6,7,8,9);
for($count1=0;$count1<9;$count1++)
{
	for($count2=0;$count2<=$count1;$count2++)
	{
		$yo=$arr1[$count1]*$arr2[$count2];

		echo "$arr1[$count1]*$arr2[$count2]=$yo&nbsp&nbsp";
	}
	echo "<br>";
}

$arr3=array("一","二","三","四","五","六","七","八","九");
$arr4=array("一","二","三","四","五","六","七","八","九"); 
$arr1 = array(1,2,3,4,5,6,7,8,9);  $arr2=array(1,2,3,4,5,6,7,8,9);
for($count1=0;$count1<9;$count1++)
{
	for($count2=0;$count2<=$count1;$count2++)
	{
		$yo=$arr1[$count1]*$arr2[$count2];

		if($yo<10)
		{
			switch($yo)
			{
				case 1: $yo="一";break;
				case 2: $yo="二";break;
				case 3: $yo="三";break;
				case 4: $yo="四";break;
				case 5: $yo="五";break;
				case 6: $yo="六";break;
				case 7: $yo="七";break;
				case 8: $yo="八";break;
				case 9: $yo="九";break;
			}
		}
		else
		{
			$yoyo=$yo%10;$yoyoyo=($yo-$yoyo)/10;
			switch($yoyo)
			{
				case 0: $yoyo=" ";break;
				case 1: $yoyo="一";break;
				case 2: $yoyo="二";break;
				case 3: $yoyo="三";break;
				case 4: $yoyo="四";break;
				case 5: $yoyo="五";break;
				case 6: $yoyo="六";break;
				case 7: $yoyo="七";break;
				case 8: $yoyo="八";break;
				case 9: $yoyo="九";break;
			}
			switch($yoyoyo)
			{
				case 1: $yoyoyo="十";break;
				case 2: $yoyoyo="二十";break;
				case 3: $yoyoyo="三十";break;
				case 4: $yoyoyo="四十";break;
				case 5: $yoyoyo="五十";break;
				case 6: $yoyoyo="六十";break;
				case 7: $yoyoyo="七十";break;
				case 8: $yoyoyo="八十";break;
			}
			$yo=$yoyoyo.$yoyo;
		}

		echo "$arr3[$count1]$arr4[$count2]得$yo&nbsp&nbsp";
	}
	echo "<br>";
}


echo "<br><br>";


//循环输出考生的编号和成绩。代码如下： $stud = array(0=>88,1=>60,3=>99,5=>66);
echo "我没有看懂流程4是什么意思。不知道让干嘛的！！！！";
	



?>